
//
// Created by liaohailong on 2024/11/30.
//

#ifndef RTSPDEMO_CSAPP_HPP
#define RTSPDEMO_CSAPP_HPP

#include <cstdlib>
#include <unistd.h>
#include <cstdio>
#include <cstring>
#include <cerrno>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define RIO_BUFFERSIZE 8192
#define LISTENQ 1024
#define MAXLINE 8192

typedef struct {
    int rio_fd; /* Descriptor for this internal buf */
    long rio_cnt; /* Unread bytes in internal buf*/
    char *rio_bufptr; /* Next unread byte in internal buf */
    char rio_buf[RIO_BUFFERSIZE]; /* Internal buf */

} rio_t;

typedef struct sockaddr SA;

ssize_t rio_readn(int fd, void *usrbuf, size_t n);
ssize_t rio_readline(int fd, void *usrbuf, size_t maxlen);
ssize_t rio_writen(int fd, void *usrbuf, size_t n);
void rio_readinitb(rio_t *rp, int fd);
ssize_t rio_read(rio_t *rp, void *usrbuf, ssize_t n);
ssize_t rio_readlineb(rio_t *rp, void *usrbuf, size_t maxlen);
ssize_t rio_readnb(rio_t *rp, void *usrbuf, ssize_t n);


/** Socket */

int open_clientfd(const char *hostname, const char *port); // TCP

int open_listenfd(const char *port); // TCP

int open_listen_udp_fd(const char *port); // UDP

#endif //RTSPDEMO_CSAPP_HPP
